﻿using System;
using System.Collections.Generic;
using MovieDB.DTOs;
using MovieDB.RepositoryInterfaces;
using MovieDB.ServiceInterfaces;

namespace MovieDB.Services
{
    public class MovieService : IMovieService
    {
        private readonly IMovieRepository _movieRepository;


        public MovieService(IMovieRepository movieRepository)
        {
            _movieRepository = movieRepository;
        }

        #region IMovieService Members

        public MovieDto GetMovieById(Guid movieId)
        {
            return _movieRepository.GetMovieById(movieId);
        }

        public PagedMovieDto GetAllMoviesPaged(int page, int pageSize)
        {
            return _movieRepository.GetAllMoviesPaged(page, pageSize);
        }

        public IEnumerable<MovieDto> GetMostRecentMovies(int amountOfRecentMovies)
        {
            if (amountOfRecentMovies <= 0)
            {
                throw new ArgumentOutOfRangeException("amountOfRecentMovies", "Only positive digits are allowed.");
            }
            return _movieRepository.GetMostRecentMovies(amountOfRecentMovies);
        }

        public void SaveMovie(MovieDto movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException("movie");
            }

            _movieRepository.SaveMovie(movie);
        }

        public void DeleteMovie(Guid movieId)
        {
            _movieRepository.DeleteMovie(movieId);
        }

        #endregion
    }
}